import {resolve} from "path"

const config = {
	projectName: "myApp",
	date: "2022-7-14",
	designWidth: 375,
	deviceRatio: {
		640: 2.34 / 2,
		750: 1,
		828: 1.81 / 2,
		375: 2 / 1
	},
	sourceRoot: "src",
	outputRoot: "dist",
	plugins: [
		"taro-plugin-compiler-optimization",
		[
			"taro-plugin-tailwind",
			{
				scan: {
					dirs: ["./src"], // 只扫描 src 目录下的文件
					exclude: ["./dist/**/*", "./src/**/**/echarts.js"] // 排除 dist 目录
				}
				// 具体参数见：https://github.com/windicss/vite-plugin-windicss/blob/main/packages/plugin-utils/src/options.ts#L10
			}
		]
	],
	defineConstants: {},
	copy: {
		patterns: [],
		options: {}
	},
	framework: "react",
	mini: {
		// 只能提取分包内使用的依赖，并将依赖打包至当前分包中，不在将分包内的依赖打包至主包中
		optimizeMainPackage: {
			enable: true
		},
		postcss: {
			pxtransform: {
				enable: true,
				config: {}
			},
			url: {
				enable: true,
				config: {
					limit: 1024 // 设定转换尺寸上限
				}
			},
			cssModules: {
				enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
				config: {
					namingPattern: "module", // 转换模式，取值为 global/module
					generateScopedName: "[name]__[local]___[hash:base64:5]"
				}
			}
		}
	},
	h5: {
		publicPath: "/",
		staticDirectory: "static",
		postcss: {
			autoprefixer: {
				enable: true,
				config: {}
			},
			cssModules: {
				enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
				config: {
					namingPattern: "module", // 转换模式，取值为 global/module
					generateScopedName: "[name]__[local]___[hash:base64:5]"
				}
			}
		}
	},
	alias: {
		"@": resolve(__dirname, "..", "src")
	},
	webpackChain(chain) {
		console.log("index webpackChain")
		chain.merge({
			plugin: {
				install: {
					plugin: require("terser-webpack-plugin"),
					args: [
						{
							terserOptions: {
								compress: true, // 默认使用terser压缩
								// mangle: false,
								keep_classnames: true, // 不改变class名称
								keep_fnames: true // 不改变函数名称
							}
						}
					],
					npm: "npm"
				}
			}
		})

		chain.optimization.sideEffects(false)
	}
}

export default function (merge) {
	if (process.env.NODE_ENV === "development") {
		return merge({}, config, require("./dev"))
	}
	return merge({}, config, require("./prod"))
}
